import { request } from "../request";

export interface QuestionItem {
    questionId: number;
    creatorId: number;
    content: string;
    options: Record<string, unknown>;
    answer: string;
    difficulty: string;
    createdAt: Record<string, unknown>;
    type: number;
}

export interface GetAllQuestionsRes {
    code: number;
    message: string;
    data: {
        total: number;
        list: QuestionItem[];
        pageNum: number;
        pageSize: number;
        size: number;
        startRow: number;
        endRow: number;
        pages: number;
        prePage: number;
        nextPage: number;
        isFirstPage: boolean;
        isLastPage: boolean;
        hasPreviousPage: boolean;
        hasNextPage: boolean;
        navigatePages: number;
        navigatepageNums: Record<string, unknown>[];
        navigateFirstPage: number;
        navigateLastPage: number;
    };
    timestamp: Record<string, unknown>;
}

const getAllQuestionsAPI = async (pageNum: number, pageSize: number): Promise<GetAllQuestionsRes> => {
    const token = localStorage.getItem("token");
    return request(`/api/questions/all`, {
        method: "get",
        headers: {
            "Content-Type": "application/json",
            "Authorization": `Bearer ${token}`,
        },
    });
};

export default getAllQuestionsAPI;
